package com.tupu.service.impl.dispatch;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tupu.entity.dispatch.StandardizationDeviceNews;
import com.tupu.mapper.dispatch.StandardizationDeviceNewsMapper;
import com.tupu.service.dispatch.StandardizationDeviceNewsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;


@Service
public class StandardizationDeviceNewsServiceImpl extends ServiceImpl<StandardizationDeviceNewsMapper, StandardizationDeviceNews> implements StandardizationDeviceNewsService {

    @Autowired(required = false)
    private StandardizationDeviceNewsMapper standardizationDeviceNewsMapper;

    @Override
    public Page<StandardizationDeviceNews> deviceNewsPage(String device_type, String station, String problem_type, Long page, Long size) {
        QueryWrapper<StandardizationDeviceNews> queryWrapper = new QueryWrapper<>();
        Page<StandardizationDeviceNews> info = new Page<>(page, size);
        if (StringUtils.isNotEmpty(device_type)) {
            queryWrapper.eq("device_type", device_type);
        }
        if (StringUtils.isNotEmpty(station)) {
            queryWrapper.eq("station", station);
        }
        if (StringUtils.isNotEmpty(problem_type)) {
            queryWrapper.eq("problem_type", problem_type);
        }
        standardizationDeviceNewsMapper.selectPage(info, queryWrapper);
        return info;
    }

    @Override
    public List<String> findAllStation() {
        List<String> list = new ArrayList<>();
        QueryWrapper<StandardizationDeviceNews> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("station");
        List<StandardizationDeviceNews> problemLists = standardizationDeviceNewsMapper.selectList(queryWrapper);
        for (StandardizationDeviceNews info : problemLists) {
            if (null != info){
                list.add(info.getStation());
            }
        }
        List<String> stringList = list.stream().distinct().collect(Collectors.toList());
        stringList.remove("");
        return stringList;
    }

    @Override
    public List<String> findAllDeviceType() {
        List<String> list = new ArrayList<>();
        list.add("开关");
        list.add("刀闸");
        list.add("保护信号");
        return list;
    }
}